/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.report.bean;

import com.yunhoo.report.model.ReportModel;
import com.yunhoo.sys.util.common.FacesUtils;
import java.util.HashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.servlet.http.HttpSession;

@ManagedBean(name = "reprotBean")
@RequestScoped
public class ReprotBean {

    /*
     * 报表类型
     */
    private String reportType = null;
    /*
     * 其他参数
     */
    private String deptCode = null;
    private Integer iyear = null;
    private Integer imonth = null;
    /*
     * 报表实体，包含表头（数组）和 数据（json）
     */
    private ReportModel reportEntity = null;

    public void queryReport() {
        /*
         * 获取报表类型
         */
        reportType = FacesUtils.getRequestParameter("reportType");
        /*
         * 用工厂类动态获取报表实现
         */
        ReportFactory reprotFactory = new ReportFactory();
        Report report = reprotFactory.produce(reportType);

        Map map = new HashMap();
        map.put("iyear", iyear);
        map.put("imonth", imonth);
        map.put("deptCode", deptCode);
        reportEntity = report.buildReport(map);

        /*
         * 将报表数据部分放入HttpSession
         */
        HttpSession session = FacesUtils.getSession();
        session.setAttribute(reportType, reportEntity.getJsonData());
    }
}
